package com.example.ragproject.tools;

import com.example.ragproject.bean.Appointment;
import com.example.ragproject.service.AppiontmentService;
import dev.langchain4j.agent.tool.Tool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class AppiontmentTools {

    @Autowired
    private AppiontmentService appiontmentService;


    @Tool
    public String bookAppiontment(Appointment appointment){
        //查找数据库中是否包含对应的预约记录
        Appointment appointmentDB = appiontmentService.getOne(appointment);
        if(appointmentDB == null){
            appointment.setId(null);
            if(appiontmentService.save(appointment)){
                return "预约成功,并返回预约详情";
            }else {
                return "预约失败";
            }
        }
        return "您在相同的科室和时间已经有预约。";
    }



    @Tool
    public String cancelAppiontment(Appointment appointment){
        Appointment appointmentDB = appiontmentService.getOne(appointment);
        if(appointmentDB != null){
            //删除预约记录
            if(appiontmentService.removeById(appointment.getId())){
                return "取消预约成功";
            }else {
                return "取消失败";
            }
        }
        return "没有这个记录";
    }







}
